home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Interplay's Learn to Program Basic (Review Copy)
/
Learn to Program Basic Review Copy (Interplay)(June 23, 1998).ISO
/
pc
/
ltpbasic
/
projects
/
concentr.bas
< prev
next >
Wrap
BASIC Source File
|
1998-02-21
|
4KB
|
216 lines
Rem Concentration
Rem The object of this game is
Rem to match up all the faces
Rem in the least possible tries.
Rem Declare the arrays, setup the sprite
Dim faces(18)
Dim grid(6,6)
Dim remap(18)
Rem This string names the
Rem background to be used
background$ = "cncntrtn"
Rem Load the face sprites
face = LoadSprite("Faces")
Rem Load the sprites for 'star'
star = LoadSprite("star")
Rem The first image in the star
Rem set is blank, the second is a star
Rem to mark where we've been
SetSprite star FRAME 0
Rem Define sounds to use
clickFirstSnd = LoadSound("BLIP2")
rightChoiceSnd = LoadSound("CASHREG")
wrongChoiceSnd = LoadSound("CARHORN2")
gameOverSound$ = "GAMOVER1"
Rem Don't show these sprites yet
HideSprite face
HideSprite star
continue = TRUE
whiteout = FALSE
Rem Outer loop - continue playing the game
Rem until the users wishes to stop
while continue
gosub SetupFaces
Position 14,0
guess = 0
score = 0
toggle = 0
oldface = 0
oldx = -1
oldy = -1
try = 0
Rem Main loop - continue choices
Rem until the user got all of the squares
go = 1
while go
if clickrect(0,0 to 319,239) then
Rem If user click the mouse, find out which grid
Rem square was clicked on
xm = mousex
ym = mousey
xt = -1
yt = -1
for x = 1 to 6
for y = 1 to 6
Rem Each rectangle is spaced
Rem 46 x 37 pixels apart
x1 = 29+((x-1)*46)
y1 = 6+((y-1)*37)
Rem and each rectangle is
Rem 32 x 34 pixels
x2 = x1 + 32
y2 = y1 + 34
if xm >= x1 and xm <= x2 and ym >= y1 and ym<=y2 then
xt = x
yt = y
endif
next y
next x
if xt <> -1 then
if grid(xt,yt) <> -1 then
Rem User click in a grid square, paste a face to it
x = xt
y = yt
pic = grid(xt,yt)
Gosub PasteFace
Rem If this is the first one to be clicked on, set a flag
if toggle = 0 then
PlaySound(clickFirstSnd)
toggle = 1
oldface = grid(xt,yt)
oldx = xt
oldy = yt
grid(xt,yt) = -1
else
Rem if this is the 2nd one, check for a match with the first
try = try + 1
toggle = 0
grid(oldx, oldy) = oldface
if grid(xt,yt) = oldface then
Rem 2 matching faces! Increase score
PlaySound(rightChoiceSnd)
grid(xt,yt) = -1
grid(oldx, oldy) = -1
score = score + 1
if score = 18 then go = 0
else
Rem 2 different faces - blank both out and go on
PlaySound(wrongChoiceSnd)
sleep 10
xsqr = oldx
ysqr = oldy
SetSprite star FRAME 1
gosub FillSquare
xsqr = xt
ysqr = yt
gosub FillSquare
SetSprite star FRAME 0
endif
endif
endif
endif
endif
wend
Rem End game - prompt if they want to try again
Rem If not, stop.
Sound gameOverSound$
color 190
fillrect 0,200 to 260,239
color 6
position 0,13
print "You got it in ";try;" tries."
input "Try again (y/n)?",a$
if lower$(left$(a$,1))="n" then continue = 0
wend
end
Rem Generate a random grid of 18 faces, and place
Rem 2 of each onto the grids
SetupFaces:
Rem Create a remap table for 18 different faces
numFrames = GetSpriteNumFrames(face)
Rem Sprite set MUST contain at least 18 images
Rem or else we won't have enough to work with
If numFrames < 18 Then
CLS
Print "The sprite set does not contain enough images!"
Endif
Rem Now, pick a random set of 18 from the images
Rem and put them into our array
For z = 1 to 18
redoremap:
remap(z) = random(0,numFrames-1)
for ctr = 1 to z-1
if remap(z) = remap(ctr) then goto redoremap
next ctr
next z
Rem set up the screen
cls
Background background$
Rem create the 6x6 grid
for z= 1 to 18
faces(z) = 0
next z
for x = 1 to 6
for y = 1 to 6
loop:
pic = random(1,18)
if faces(pic) = 2 then goto loop
faces(pic) = faces(pic) + 1
grid(x,y) = pic
xsqr = x
ysqr = y
gosub FillSquare
next y
next x
return
Rem Put a sprite into the x,y specified grid square
PasteFace:
whiteout = TRUE
xsqr = x
ysqr = y
gosub FillSquare
SetSprite face frame remap(pic)
SetSprite face to 29+((x-1)*46), 6+((y-1)*37)
PasteSprite face
SetSprite face to -100,-100
return
Rem Clear the graphics from a specific square
Rem If whiteout is 1, fill it with white,
Rem Otherwise, mark it with a star
FillSquare:
x1 = 28+((xsqr-1)*46)
y1 = 6+((ysqr-1)*37)
If whiteout = TRUE then
x2 = x1 + 32
y2 = y1 + 31
color 6
FillRect x1,y1 to x2,y2
whiteout = FALSE
else
SetSprite star to x1,y1
ShowSprite star
PasteSprite star
HideSprite star
endif
return